package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.tongbing.config.*;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.activity.TongBingProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.List;

public class TongBingPb {

    public static TongBingProto.TongBingSyncConfigRespMsg.Builder parseTongBingSyncConfigRespMsg(TongBingConfig config, String language) {
        TongBingProto.TongBingSyncConfigRespMsg.Builder builder = TongBingProto.TongBingSyncConfigRespMsg.newBuilder();
        for (TongBingBuffTypeConfig buffTypeConfig : config.getBuffTypeConfigMap().values()) {
            builder.addBuffTypeConfig(TongBingPb.parseTongBingBuffTypeConfigMsg(buffTypeConfig, language));
        }
        for (TongBingCityTypeConfig cityTypeConfig : config.getCityTypeConfigMap().values()) {
            builder.addCityTypeConfig(TongBingPb.parseTongBingCityTypeConfigMsg(cityTypeConfig, language));
        }
        for (TongBingCityConfig cityConfig : config.getCityConfigMap().values()) {
            builder.addCityConfig(TongBingPb.parseTongBingCityConfigMsg(cityConfig, language));
        }
        for (TongBingNpcEventConfig npcEventConfig : config.getNpcEventConfigMap().values()) {
            builder.addNpcEventConfig(TongBingPb.parseTongBingNpcEventConfigMsg(npcEventConfig));
        }
        for (TongBingTitleConfig titleConfig : config.getTitleConfigMap().values()) {
            builder.addTitleConfig(TongBingPb.parseTongBingTitleConfigMsg(titleConfig, language));
        }
        return builder;
    }

    public static TongBingProto.TongBingBuffTypeConfigMsg.Builder parseTongBingBuffTypeConfigMsg(TongBingBuffTypeConfig config, String language) {
        TongBingProto.TongBingBuffTypeConfigMsg.Builder builder = TongBingProto.TongBingBuffTypeConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setBuffType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setBuffEffect(config.getBuffEffect());
        builder.setContinueTime((int) (config.getContinueTime() / DateHelper.HOUR_MILLIONS));
        return builder;
    }

    public static TongBingProto.TongBingCityTypeConfigMsg.Builder parseTongBingCityTypeConfigMsg(TongBingCityTypeConfig config, String language) {
        TongBingProto.TongBingCityTypeConfigMsg.Builder builder = TongBingProto.TongBingCityTypeConfigMsg.newBuilder();
        builder.setCityType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setFoodProduction(config.getFoodProduction());
        builder.setTeamNum(config.getTeamNum());
        builder.setSoldierNum(config.getSoldierNum());
        builder.setAddition(config.getAddition());
        builder.setBuffEffect(String.valueOf(config.getBuffEffect()));
        builder.setCampScore(config.getCampPoint());
        builder.setExtraTeamNum(config.getExtraTeamNum());
        return builder;
    }

    public static TongBingProto.TongBingCityConfigMsg.Builder parseTongBingCityConfigMsg(TongBingCityConfig config, String language) {
        TongBingProto.TongBingCityConfigMsg.Builder builder = TongBingProto.TongBingCityConfigMsg.newBuilder();
        builder.setCityId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setMapType(config.getMapType());
        builder.setCityType(config.getType());
        builder.setInitialCamp(config.getInitialCamp());
        builder.setShowType(config.getShowType());
        builder.setSpecialAddition(config.getSpecialAddition());
        return builder;
    }

    public static TongBingProto.TongBingNpcEventConfigMsg.Builder parseTongBingNpcEventConfigMsg(TongBingNpcEventConfig config) {
        TongBingProto.TongBingNpcEventConfigMsg.Builder builder = TongBingProto.TongBingNpcEventConfigMsg.newBuilder();
        builder.setEventId(config.getId());
        builder.setEventType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setRewards(config.getRewards());
        return builder;
    }


    public static TongBingProto.TongBingTitleConfigMsg.Builder parseTongBingTitleConfigMsg(TongBingTitleConfig config, String language) {
        TongBingProto.TongBingTitleConfigMsg.Builder builder = TongBingProto.TongBingTitleConfigMsg.newBuilder();
        builder.setTitleId(config.getId());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setType(config.getType());
        builder.setEffect(config.getEffect());
        builder.setRewards(config.getRewards());
        return builder;
    }

    /**
     * 获取战力同步门客列表
     */
    public static List<TongBingProto.TongBingPatronsTempMsg> parseTongBingPatronsListMsg(List<UserPatrons> userPatronsList) {
        List<TongBingProto.TongBingPatronsTempMsg> list = new ArrayList<>();
        for (UserPatrons userPatrons : userPatronsList) {
            TongBingProto.TongBingPatronsTempMsg.Builder tempBuilder = TongBingProto.TongBingPatronsTempMsg.newBuilder();
            tempBuilder.setId(userPatrons.getPatronsId());
            tempBuilder.setSkin(userPatrons.getSkinId());
            tempBuilder.setAbility(userPatrons.getAbility().longValue());
            list.add(tempBuilder.build());
        }
        return list;
    }

}
